def function-Name(self,argument,...,argument=value): Statements ---------- return value
class rectangle { private int length,breadth; public void area() { int a=length*breadth; System.out.println("Area is "+a); } public void perimeter() { int p=2*(length+breadth); System.out.println("perimerter is"+p); } public void setdimension(int m,int n) { length=m; breadth=n; } } class demo { public static void main(String args[]) { rectangle a, b ; a = new rectangle(); b=new rectangle(); a.setdimension(5,7); b.setdimension(10,20); a.area(); a.perimeter(); b.area(); } }
Area is 35 Perimeter is 24 Area is 200
class Circle { private int radius; public void area() { double a=3.14*radius *radius; System.out.println("Area is "+a); } public void circumference() { double c=2*3.14*radius; System.out.println("circumference is"+c); } public void setRadius(int n) { radius=n; } } class demo { public static void main(String args[]) { Circle a; a=new Circle(); a.setRadius(5); a.area(); a.circumference(); } }
Area is 78.5 Circumference is 31.4
class Box { int L,B,H; public void volume() { int v=L*B*H; System.out.println("Volume is "+v); } public void setDimension(int x,int y,int z) { L=x; B=y; H=z; } } class demo { public static void main(String args[]) { Box a,b; a=new Box(); b=new Box(); a.setdimension(3,4,5); b.setdimension(7,8,2); a.volume(); b.volume(); } }
Volume is 60 Volume is 112
class Account: def setData(self,an,bal): self.accno=an self.balance=bal def interest(self,r,n=1): si=self.balance*r*n/100 print("Interest is ",si) a=Account( ) a.setData(4117,25000) a.interest(10.25,3) a.interest(10.25)
Interest is 6768.50 Interest is 2562.50
class Worker: def setData(self,nm,wg,wd=7): self.name=nm self.wages=wg self.wdays=wd def showData(self): print("Name is",self.name) print("Wages is",self.wages) print("Wdays is",self.wdays) def payment(self): p=self.wages*self.wdays print("Payment is",p) a=Worker() b=Worker() a.setData("Raja",500,5) b.setData("Gaja",400) a.showData() a.payment() b.showData() b.payment()
Name is Raja Wages is 500 Wdays are 5 Payment is 2500 Name is Gaja Wages is 400 Wdays are 7 Payment is 2800